package com.ruoyi.project.im.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.im.domain.ImTemporaryMessage;
import com.ruoyi.project.im.service.IImTemporaryMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 临时消息Controller
 *
 * @author hongwj
 * @date 2024-04-16
 */
@RestController
@RequestMapping("/im/temporaryMessage" )
@Slf4j
public class ImTemporaryMessageController extends BaseController {
    @Autowired
    private IImTemporaryMessageService imTemporaryMessageService;

    /**
     * 查询临时消息列表
     */
    @PreAuthorize("@ss.hasPermi('im:temporaryMessage:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(ImTemporaryMessage imTemporaryMessage) {
        startPage();
        List<ImTemporaryMessage> list = imTemporaryMessageService.selectImTemporaryMessageList(imTemporaryMessage);
        return getDataTable(list);
    }

    /**
     * 查询所有临时消息列表
     */
    @PreAuthorize("@ss.hasPermi('im:temporaryMessage:all')" )
    @Log(title = "临时消息" , businessType = BusinessType.OTHER)
    @GetMapping("/all/temporaryMessages" )
    public AjaxResult all(ImTemporaryMessage imTemporaryMessage) {
        List<ImTemporaryMessage> list = imTemporaryMessageService.selectImTemporaryMessageList(imTemporaryMessage);
        return success(list);
    }

    /**
     * 导出临时消息列表
     */
    @PreAuthorize("@ss.hasPermi('im:temporaryMessage:export')" )
    @Log(title = "临时消息" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, ImTemporaryMessage imTemporaryMessage) {
        List<ImTemporaryMessage> list = imTemporaryMessageService.selectImTemporaryMessageList(imTemporaryMessage);
        ExcelUtil<ImTemporaryMessage> util = new ExcelUtil<ImTemporaryMessage>(ImTemporaryMessage. class);
        util.exportExcel(response, list, "临时消息数据" );
    }

    /**
     * 获取临时消息详细信息
     */
    @PreAuthorize("@ss.hasPermi('im:temporaryMessage:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return success(imTemporaryMessageService.selectImTemporaryMessageById(id));
    }

    /**
     * 新增临时消息
     */
    @PreAuthorize("@ss.hasPermi('im:temporaryMessage:add')" )
    @Log(title = "临时消息" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ImTemporaryMessage imTemporaryMessage) {
        return toAjax(imTemporaryMessageService.insertImTemporaryMessage(imTemporaryMessage));
    }

    /**
     * 修改临时消息
     */
    @PreAuthorize("@ss.hasPermi('im:temporaryMessage:edit')" )
    @Log(title = "临时消息" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ImTemporaryMessage imTemporaryMessage) {
        return toAjax(imTemporaryMessageService.updateImTemporaryMessage(imTemporaryMessage));
    }

    /**
     * 删除临时消息
     */
    @PreAuthorize("@ss.hasPermi('im:temporaryMessage:remove')" )
    @Log(title = "临时消息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(imTemporaryMessageService.deleteImTemporaryMessageByIds(ids));
    }
}
